<?php
// $Id: hotel_album.php 368 2012-05-17 03:14:05Z tomqin@gmail.com $

defined('IN_ADMIN') or exit('Access Denied!');

class Album_Action extends Action_Admin{
    var $shop_id;

    public function init(){
        parent::init();

        $this->shop_id = intval($this->params);
        $this->setVar('shop_id', $this->shop_id);

        $this->album = App::module('table_album', 'table', array($this->user));
        if(!$this->album->check_user_right($this->shop_id)){
            $this->renderDialog('您无权管理此酒店信息！');
        }
    }

    public function onModify(){
        $this->setVar('show_validator', 1);

        list( , $album_id) = explode('-', $this->params);
        $data = $this->album->get_data($this->shop_id, $album_id);
        if($data){
            $this->setVar('data', $data);
            $this->render('admin/album/edit');
        }else{
            $this->renderDialog('图片不存在，无法读取信息！');
        }
    }

    public function onList(){
        $album_cat = array_get_int($_GET, 'album_cat');
        if($album_cat){
            $list = $this->album->get_list($this->shop_id, $album_cat);
            $this->setVar('list', $list);
            $this->setVar('album_cat', $album_cat);
            $this->render('admin/album/list');
        }else{//第一层
            header("Location: /admin/album_cat/list/{$this->shop_id}");
        }
    }

    public function onImport(){
        $this->setVar('cats', $this->album->get_list_cat($this->shop_id));
        $this->setVar('album_cat', array_get_int($_GET, 'album_cat'));
        $this->setVar('show_validator', 1);
        $this->render('admin/album/import');
    }

    public function onDelete(){
        $this->album->delete($this->shop_id, array_get_int($_GET, 'album_id'));
        $this->renderDialog('删除成功！', '/admin/hotel_album/list/'.$this->shop_id);
    }

    public function onSave(){
        if(array_get_bool($_POST, 'dosubmit')){
            switch(array_get_string($_POST, 'method')){
                case 'modify':
                    $album_id = intval($_POST['album_id']);
                    $this->album->update($this->shop_id, $album_id, $_POST);
                    $this->renderDialog('修改成功！', '', 'edit');
                break;
                case 'import':
                    $this->album->import($this->shop_id, array_get_int($_POST, 'album_cat'), $_POST);
                    $this->renderDialog('上传成功！', '', 'add');
                break;
            }
        }else{
            $this->renderDialog('无效的参数！');
        }
    }

    public function onSortlist(){
        if(array_get_bool($_POST, 'dosubmit')){
            $list = $this->album->sort($this->shop_id, array_get($_POST, 'sorts'));
        }
        $list = $this->onList();
    }

    function __destruct(){}
}
?>